package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.domain.vo.SysEngineeringFileVo;
import jakarta.servlet.http.HttpServletResponse;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysEngineeringFile;
import com.ruoyi.system.service.ISysEngineeringFileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工程文件Controller
 *
 * @author ruoyi
 * @date 2025-08-29
 */
@RestController
@RequestMapping("/system/file")
public class SysEngineeringFileController extends BaseController
{
    @Autowired
    private ISysEngineeringFileService sysEngineeringFileService;

    /**
     * 查询工程文件列表
     */
    @PreAuthorize("@ss.hasPermi('system:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysEngineeringFile sysEngineeringFile)
    {
        startPage();
        List<SysEngineeringFileVo> list = sysEngineeringFileService.selectSysEngineeringFileList(sysEngineeringFile);
        return getDataTable(list);
    }

    /**
     * 导出工程文件列表
     */
    @PreAuthorize("@ss.hasPermi('system:file:export')")
    @Log(title = "工程文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysEngineeringFile sysEngineeringFile)
    {
        List<SysEngineeringFileVo> list = sysEngineeringFileService.selectSysEngineeringFileList(sysEngineeringFile);
        ExcelUtil<SysEngineeringFileVo> util = new ExcelUtil<SysEngineeringFileVo>(SysEngineeringFileVo.class);
        util.exportExcel(response, list, "工程文件数据");
    }

    /**
     * 获取工程文件详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:file:query')")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") Long fileId)
    {
        return success(sysEngineeringFileService.selectSysEngineeringFileByFileId(fileId));
    }

    /**
     * 新增工程文件
     */
    @PreAuthorize("@ss.hasPermi('system:file:add')")
    @Log(title = "工程文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysEngineeringFile sysEngineeringFile)
    {
        return toAjax(sysEngineeringFileService.insertSysEngineeringFile(sysEngineeringFile));
    }

    /**
     * 修改工程文件
     */
    @PreAuthorize("@ss.hasPermi('system:file:edit')")
    @Log(title = "工程文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysEngineeringFile sysEngineeringFile)
    {
        return toAjax(sysEngineeringFileService.updateSysEngineeringFile(sysEngineeringFile));
    }

    /**
     * 删除工程文件
     */
    @PreAuthorize("@ss.hasPermi('system:file:remove')")
    @Log(title = "工程文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable Long[] fileIds)
    {
        return toAjax(sysEngineeringFileService.deleteSysEngineeringFileByFileIds(fileIds));
    }

    @PreAuthorize("@ss.hasPermi('system:file:appList')")
    @GetMapping("/app_list")
    public AjaxResult appList()
    {
        List<SysEngineeringFileVo> list = sysEngineeringFileService.selectSysEngineeringFileList(null);
        return AjaxResult.success(list);
    }
}
